package com.github.tzraeq;

import com.facebook.react.uimanager.SimpleViewManager;
import com.facebook.react.uimanager.ThemedReactContext;
import com.ksyun.media.player.IMediaPlayer;
import com.ksyun.media.player.KSYTextureView;

import java.io.IOException;

public class RNKsyMediaPlayerManager extends SimpleViewManager<KSYTextureView> implements IMediaPlayer.OnPreparedListener {

    public static final String REACT_CLASS = "RNKsyMediaPlayer";

    @Override
    public String getName() {
        return REACT_CLASS;
    }

    @Override
    protected KSYTextureView createViewInstance(ThemedReactContext reactContext) {
        KSYTextureView view = new KSYTextureView(reactContext);
        try {
            view.setDataSource("rtsp://184.72.239.149/vod/mp4://BigBuckBunny_175k.mov");
            view.setOnPreparedListener(this);
            view.prepareAsync();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return view;
    }

    @Override
    public void onPrepared(IMediaPlayer iMediaPlayer) {
        iMediaPlayer.start();
    }
}
